from django.contrib import admin

from .models import Banner, Category,Category2, Tag, Tui, Article, Link ,Level, Web, Vip,History,Collection, Contact,Order, Ad, Page
#导入需要管理的数据库表

@admin.register(Article)
class ArticleAdmin(admin.ModelAdmin):
    list_display = ('id','web', 'category', 'category2','title', 'views','level', 'created_time')
    # 文章列表里显示想要显示的字段
    list_per_page = 50
    # 满50条数据就自动分页
    ordering = ('-created_time',)
    #后台数据列表排序方式
    list_display_links = ('id', 'title')
    # 设置哪些字段可以点击进入编辑界面
    def level(self, obj):
        return u'%s' % obj.Level.name
    level.short_description = u'等级'

    def web(self, obj):
        return u'%s' % obj.Web.name
    web.short_description = u'子网站'



# @admin.register(Banner)
# class BannerAdmin(admin.ModelAdmin):
#     list_display = ('id', 'text_info', 'img', 'link_url', 'is_active')

@admin.register(Category)
class CategoryAdmin(admin.ModelAdmin):
    list_display = ('id', 'web','name', 'index')

@admin.register(Category2)
class Category2Admin(admin.ModelAdmin):
    list_display = ('id','category', 'name', 'index')

@admin.register(Tag)
class TagAdmin(admin.ModelAdmin):
    list_display = ('id', 'name')

# @admin.register(Tui)
class TuiAdmin(admin.ModelAdmin):
    list_display = ('id', 'name')

@admin.register(Level)
class LevelAdmin(admin.ModelAdmin):
    list_display = ('id', 'name')

@admin.register(Web)
class WebAdmin(admin.ModelAdmin):
    list_display = ('id', 'name')

@admin.register(Link)
class LinkAdmin(admin.ModelAdmin):
    list_display = ('id', 'name','linkurl')

@admin.register(Vip)
class VipAdmin(admin.ModelAdmin):
    list_display = ('id', 'user','web','kind','start_time','end_time')
    readonly_fields = ('end_time',)

@admin.register(History)
class HistoryAdmin(admin.ModelAdmin):
    list_display = ('id', 'user','article','created_time')
    # readonly_fields = ('end_time',)

@admin.register(Collection)
class CollectionAdmin(admin.ModelAdmin):
    list_display = ('id', 'user','article')
    # readonly_fields = ('end_time',)

@admin.register(Contact)
class ContactAdmin(admin.ModelAdmin):
    list_display = ('id', 'user','truename','email','phone','company_name','company_address','company_address','context','context','created_time')
    readonly_fields = ('id', 'user','truename','email','phone','company_name','created_time','company_address','context')

@admin.register(Order)
class OrderAdmin(admin.ModelAdmin):
    list_display = ('id', 'user','truename','email','phone','company_name','web0','web1','web2','web3','web4','web5','web6','web7','web8','web9','pay_type','price','complete','created_time')
    readonly_fields = ('id', 'user','truename','email','phone','company_name','web0','web1','web2','web3','web4','web5','web6','web7','web8','web9','created_time','price','pay_type')

@admin.register(Banner)
class BannerAdmin(admin.ModelAdmin):
    list_display = ('id', 'text_info','zone','img','link_url', 'is_active')

@admin.register(Ad)
class AdAdmin(admin.ModelAdmin):
    ordering = ('id',)
    list_display = ('id', 'name','url', 'img', 'is_active')

@admin.register(Page)
class PageAdmin(admin.ModelAdmin):
    list_display = ('name', 'index', 'link')
    list_display_links = ('name',)

admin.site.site_header = '时视化工管理后台'  # 设置header
admin.site.site_title = '时视化工管理后台'  # 设置title
admin.site.index_title = '时视化工管理后台'
